


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > Ghost</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.npc</a>
</div>

<h1>Coverage Summary for Class: Ghost (nl.tudelft.jpacman.npc)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Ghost</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/17)
  </span>
</td>
</tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$17QxBwzj</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$2gfWDxKk</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$5gdIQN1E</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$93mnZ6oZ</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$AFe0rnGA</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$CvxeAsJB</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$dvnETMh2</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$GPGub0sL</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$iEpq6M7u</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$K0agq3Gh</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$NRwrlIwH</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$wlN0e9Mu</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$xVFVDB2O</td>
  </tr>
  <tr>
    <td class="name">Ghost$MockitoMock$365055219$auxiliary$xYmmVcBt</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/17)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman.npc;
&nbsp;
&nbsp;import nl.tudelft.jpacman.board.Direction;
&nbsp;import nl.tudelft.jpacman.board.Square;
&nbsp;import nl.tudelft.jpacman.board.Unit;
&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
&nbsp;
&nbsp;import java.util.ArrayList;
&nbsp;import java.util.List;
&nbsp;import java.util.Map;
&nbsp;import java.util.Optional;
&nbsp;import java.util.Random;
&nbsp;
&nbsp;/**
&nbsp; * A non-player unit.
&nbsp; *
&nbsp; * @author Jeroen Roosen
&nbsp; */
&nbsp;public abstract class Ghost extends Unit {
&nbsp;    /**
&nbsp;     * The sprite map, one sprite for each direction.
&nbsp;     */
&nbsp;    private final Map&lt;Direction, Sprite&gt; sprites;
&nbsp;
&nbsp;    /**
&nbsp;     * The base move interval of the ghost.
&nbsp;     */
&nbsp;    private final int moveInterval;
&nbsp;
&nbsp;    /**
&nbsp;     * The random variation added to the {@link #moveInterval}.
&nbsp;     */
&nbsp;    private final int intervalVariation;
&nbsp;
&nbsp;    /**
&nbsp;     * Calculates the next move for this unit and returns the direction to move
&nbsp;     * in.
&nbsp;     * &lt;p&gt;
&nbsp;     * Precondition: The NPC occupies a square (hasSquare() holds).
&nbsp;     *
&nbsp;     * @return The direction to move in, or &lt;code&gt;null&lt;/code&gt; if no move could
&nbsp;     * be devised.
&nbsp;     */
&nbsp;    public Direction nextMove() {
<b class="nc">&nbsp;        return nextAiMove().orElseGet(this::randomMove);</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Tries to calculate a move based on the behaviour of the npc.
&nbsp;     *
&nbsp;     * @return an optional containing the move or empty if the current state of the game
&nbsp;     * makes the ai move impossible
&nbsp;     */
&nbsp;    public abstract Optional&lt;Direction&gt; nextAiMove();
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new ghost.
&nbsp;     *
&nbsp;     * @param spriteMap         The sprites for every direction.
&nbsp;     * @param moveInterval      The base interval of movement.
&nbsp;     * @param intervalVariation The variation of the interval.
&nbsp;     */
<b class="nc">&nbsp;    protected Ghost(Map&lt;Direction, Sprite&gt; spriteMap, int moveInterval, int intervalVariation) {</b>
<b class="nc">&nbsp;        this.sprites = spriteMap;</b>
<b class="nc">&nbsp;        this.intervalVariation = intervalVariation;</b>
<b class="nc">&nbsp;        this.moveInterval = moveInterval;</b>
<b class="nc">&nbsp;    }</b>
&nbsp;
&nbsp;    @Override
&nbsp;    public Sprite getSprite() {
<b class="nc">&nbsp;        return sprites.get(getDirection());</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * The time that should be taken between moves.
&nbsp;     *
&nbsp;     * @return The suggested delay between moves in milliseconds.
&nbsp;     */
&nbsp;    public long getInterval() {
<b class="nc">&nbsp;        return this.moveInterval + new Random().nextInt(this.intervalVariation);</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Determines a possible move in a random direction.
&nbsp;     *
&nbsp;     * @return A direction in which the ghost can move, or &lt;code&gt;null&lt;/code&gt; if
&nbsp;     * the ghost is shut in by inaccessible squares.
&nbsp;     */
&nbsp;    protected Direction randomMove() {
<b class="nc">&nbsp;        Square square = getSquare();</b>
<b class="nc">&nbsp;        List&lt;Direction&gt; directions = new ArrayList&lt;&gt;();</b>
<b class="nc">&nbsp;        for (Direction direction : Direction.values()) {</b>
<b class="nc">&nbsp;            if (square.getSquareAt(direction).isAccessibleTo(this)) {</b>
<b class="nc">&nbsp;                directions.add(direction);</b>
&nbsp;            }
&nbsp;        }
<b class="nc">&nbsp;        if (directions.isEmpty()) {</b>
<b class="nc">&nbsp;            return null;</b>
&nbsp;        }
<b class="nc">&nbsp;        int i = new Random().nextInt(directions.size());</b>
<b class="nc">&nbsp;        return directions.get(i);</b>
&nbsp;    }
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-04-25 17:20</div>
</div>
</body>
</html>
